﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using RoofRunner.GameComponents;
using RoofRunner.GameComponents.Rendering;

namespace RoofRunner.Actors.ActorComponents
{
    public class ActorComponentList : List<ActorComponent>
    {

        #region Methods
        public void LoadContent(ContentManager content)
        {
            foreach (var c in this)
                c.LoadContent(content);
        }


        public void Update(GameTime gameTime)
        {
            var sorted = this.OrderByDescending(x => x.UpdatePriority);
            foreach (var c in sorted)
                c.Update(gameTime);
        }

        public void PreRender(GameTime gameTime)
        {
            foreach (var x in this)
                x.PreRender(gameTime);
        }

        public void Render(GameTime gameTime, RenderWorld renderWorld)
        {
            var sorted = this.OrderByDescending(x => x.RenderPriority);
            foreach (var c in sorted)
                c.Render(gameTime, renderWorld);
        }



        public void SetOwnerActor(Actor a)
        {
            foreach (var c in this)
                c.Parent = a;
        }
        #endregion // Methods
    }
}
